{extend name='public/content'}

{block name="title"}
	立即支付
{/block}
{block name="body"}
	
<div class="layui-container"> 
	{foreach(orderdetaile as $key=>$val)}
		<div class="layui-row">
		    <div class="layui-col-md6">
		     	{$val.goods.name}
		    </div>
		    <div class="layui-col-md6">
		      <img src="{$val.goods.logo}" style="width: 100px;height: 100px">
		    </div>
		     <div class="layui-col-md6">
		     	{$val.goods.description}
		    </div>	
		     <div class="layui-col-md6">
		     	{$val.goods.detail}
		    </div>
		    <div class="layui-col-md6">
		     	数量：{$val.goods_num}
		     	单价：{$val.spec_price}
		     	总价：{$val.final_amount}
		    </div>	
		</div>
	{/foreach}


</div>

<div>

	
</div>	
<div class="layui-container">  
	 	
		  <div class="layui-row">
		    <div class="layui-col-xs3">
		     <!--  <img src="" style="width: 80px;height: 70px"> -->
		    </div>
		    <div class="layui-col-xs3">
		     	
		    </div>
		    <div class="layui-col-xs3">
		     	
		    </div>
		    <div class="layui-col-xs3 layui-btn layui-btn-warm shiyongycard" 
		    				data-isuse="1" data-id="{v.id}" 
		    				data-amount="{v.amount}">
		     	

		    </div>
	 	  </div>
	 	
   </div>

支付类型
<div class="layui-container">  
{foreach($paytype as $v)}
	 <button class="layui-row paytype" data-payid="{$v.value}">
	 	{$v.detail}
	 </button>	

{/foreach}
</div>
<!-- 支付宝 -->
<form action="{:url('alipay/pay')}" method="POST" id="alipay"  style="display: none;">
	<input type="hidden" name="order_sn" value="{$order.order_sn}">
	
	<input type="hidden" name="final_amount" value="0.01">
</form>
<!-- 微信支付 -->
<form action="{:url('weixinpay/weixin_pay')}" method="POST" id="weixin" style="display: none;">
	<input type="hidden" name="order_sn" value="{$order.order_sn}">	
	<input type="hidden" name="final_amount" value="{$order.final_amount}">
</form>
<!-- 余额支付 -->
<form action="{:url('pay/pay')}" method="POST" id="yuezhifu"  style="display: none;">
	<input type="hidden" name="orderid" value="{$order.id}">
	<input type="hidden" name="pay" value="">
	<input type="hidden" name="final_amount" value="{$order.final_amount}">
</form>总金额:
	<div class="amount" data-mount="{$order.goods_price}">{$order.goods_price}</div>
	订单号	    => 			{$order.order_sn}
	订单号      => 			{$order.order_sn}
<button class="payliji">立即支付</button>
{/block}

{block name="script"}
<script type="text/javascript">
require(['jquery'], function () {
	 		
	/**
	 * 点击支付
	 * @param  {[type]}
	 * @return {[type]}
	 */
	$('.payliji').click(function(event){
		var pay  = $('input[name=pay]').val();
			if( pay == ''){
				alert("请选择支付类型");
				return;
			}
			//支付宝
			if(pay==1){
				var psotdata = $('form').serialize();
		 		console.dir(psotdata);
		 		$('#alipay').submit();
			}

			//微信支付
			if(pay==2){
				var psotdata = $('form').serialize();
		 		console.dir(psotdata);
		 		$('#weixin').submit();
			}
			//月余额支付
			if(pay == 3){
				var shiyongycard =$('.shiyongycard');
				shiyongycard.each(function(index, el) {
					if($(el).attr('data-isuse')=='0'){
						let input = '<input type="hidden" name="check['+$(el).attr('data-id')+']" value="'+$(el).attr('data-id')+'">'
						$('#yuezhifu').append(input);	
					}
				});
		 		var psotdata = $('form').serialize();
		 		console.dir(psotdata);
		 		$('#yuezhifu').submit();
			}	
	});

	 	/**
	 	 * 获取支付形式
	 	 * @param  {[type]}   
	 	 * @return {[type]}
	 	 */
		$('.paytype').click(function(event) {
		$('input[name=pay]').val($(this).data('payid'))
		
		});

		/**
		 * 是用优惠券
		 * @param  {[type]} event) {	           					 			} [description]
		 * @return {[type]}        [description]
		 */
		 
		$('.shiyongycard').click(function(event) {
			var that= $(this);
			var amount = that.data('amount');
			var tomount =$('.amount').text();
			var isuse = that.attr('data-isuse');
			console.dir(isuse);
			if(isuse=="1"){
				var totle = parseInt(tomount)-parseInt(amount);
				$('.amount').text(totle);
			that.attr('data-isuse',"0");
			isuse=false;
			}else{
				var totle = parseInt(tomount)+parseInt(amount);
				$('.amount').text(totle);
				that.attr('data-isuse',"1");
				isuse =true;
			}
		});
})
</script>
{/block}
	
{block name="style"}
 <style type="text/css">
 	
 </style>
{/block}
